/*
 * Copyright 2017 Zhihu Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zhihu.matisse.library.slice;

import com.zhihu.matisse.library.model.Item;
import com.zhihu.matisse.library.model.SelectionSpec;
import com.zhihu.matisse.library.provider.PreviewProvider;
import ohos.aafwk.content.Intent;

import java.util.ArrayList;

import static com.zhihu.matisse.library.model.SelectedItemCollection.STATE_SELECTION;

public class SelectPreviewAbility extends BasePreviewAbility{

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        if (!SelectionSpec.getInstance().hasInited) {
            terminateAbility(0);
            return;
        }
        ArrayList<Item> selected = getIntent().getParcelableArrayListParam(STATE_SELECTION);
        if (selected != null){
            if (previewProvider == null){
                previewProvider = new PreviewProvider(getContext(),selected);
                pageSlider.setProvider(previewProvider);
            }else {
                previewProvider.addAll(selected);
            }
            previewProvider.notifyDataChanged();
            if (mSpec.countable) {
                mCheckView.setCheckedNum(1);
            } else {
                mCheckView.setChecked(true);
            }
            mPreviousPos = 0;
            updateSize(selected.get(0));
        }
    }

}
